﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using AwesomeEnginePC.Physics;

namespace AwesomeEnginePC.Graphics.TwoDimensional
{
    public abstract class Base2DObject : BaseGraphicalObject
    {
        /// <summary>
        /// The x-y position of the object
        /// </summary>
        public Vector Position { get; set; }
        /// <summary>
        /// The layer depth of the object.
        /// </summary>
        public virtual float LayerDepth { get; set; }

        /// <summary>
        /// A Point that describes the origin of the object. 
        /// Remember to use RawHeight and RawWidth instead of regular Height and Width; this value is calculated before any scaling is applied.
        /// </summary>
        public virtual Vector Origin { get; set; }

        /// <summary>
        /// The rotation of the object, in Radians.
        /// </summary>
        public virtual float Rotation { get; set; }

        /// <summary>
        /// The scaling of the draw object on the X axis.
        /// </summary>
        public virtual float ScalingX { get; set; }

        /// <summary>
        /// The scaling of the draw object on the Y axis.
        /// </summary>
        public virtual float ScalingY { get; set; }

        /// <summary>
        /// The Tint of the object, with default white. If object is a font, this property is the color of its text, with default black.
        /// </summary>
        public virtual Color Tint { get; set; }

        /// <summary>
        /// The drawn height of the object. Does take into consideration the object's scaling.
        /// </summary>
        public abstract int Height { get; set; }

        /// <summary>
        /// The drawn width of the object. Does take into consideration the object's scaling.
        /// </summary>
        public abstract int Width { get; set; }

        public Base2DObjectSettings GetBase2DObjectSettings()
        {
            return new Base2DObjectSettings()
            {
                Position = this.Position,
                LayerDepth = this.LayerDepth,
                Origin = this.Origin,
                Rotation = this.Rotation,
                ScalingX = this.ScalingX,
                ScalingY = this.ScalingY,
                Tint = this.Tint,
            };
        }

        public void LoadFromSettings(Base2DObjectSettings settings)
        {
            Position = settings.Position;
            LayerDepth = settings.LayerDepth;
            Origin = settings.Origin;
            Rotation = settings.Rotation;
            ScalingX = settings.ScalingX;
            ScalingY = settings.ScalingY;
            Tint = settings.Tint;
        }

        protected virtual void SetDefaultValues()
        {
            ContentAssetName = null;
            Position = new Vector();
            Tint = Color.White;
            Rotation = 0f;
            Origin = new Vector();
            LayerDepth = 0f;
            ScalingX = 1;
            ScalingY = 1;
        }

        public Base2DObject(ContentManager cm)
            : base(cm)
        {
            SetDefaultValues();
        }
    }
}
